package com.hongkzh.www.look.enterprise.watch.view.adapter;

import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hongkzh.www.R;
import com.hongkzh.www.look.enterprise.userinfo.model.bean.MediaProductBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by asad on 2018/3/27.
 * 看视频 产品 adapter
 */

public class WCPRvAdapter extends RecyclerView.Adapter<WCPRvAdapter.ViewHolder> {
    private List<MediaProductBean.DataBean.ListBean> data;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_wcprv, parent, false));
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Glide.with(holder.itemView).load(data.get(position).getImgSrc()).into(holder.wcrIma);
        holder.wcrTitle.setText(data.get(position).getTitle());
        holder.wcrSubtitle.setText(data.get(position).getSubtitle());

        String state = data.get(position).getState();
        if (!TextUtils.isEmpty(state) && "1".equals(state)) {
            holder.wcrNum.setText("已预约 " + data.get(position).getPreorderNum() + "人");
            holder.wcrState.setImageResource(R.mipmap.watch_yuyue);
        } else if ("2".equals(state)) {
            holder.wcrNum.setText("已购买 " + data.get(position).getOrderNum() + "人");
            holder.wcrState.setImageResource(R.mipmap.watch_goumai);
        }
    }

    @Override
    public int getItemCount() {
        return data == null ? 0 : data.size();
    }

    public void add(MediaProductBean mediaProductBean) {
        if (mediaProductBean.getData().isFirstPage()) {
            data = mediaProductBean.getData().getList();
        } else {
            data.addAll(mediaProductBean.getData().getList());
        }
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.wcr_ima)
        ImageView wcrIma;
        @BindView(R.id.wcr_title)
        TextView wcrTitle;
        @BindView(R.id.wcr_subtitle)
        TextView wcrSubtitle;
        @BindView(R.id.wcr_num)
        TextView wcrNum;
        @BindView(R.id.wcr_state)
        ImageView wcrState;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
